var ID = 0;

document.getElementById("welcome").onclick = function(e) {

	var welcome = document.getElementById("welcome");
	welcome.style.transform = "rotate(715deg) scale(0.5)";
	$('#welcome').css({
		'top': '0',
		'left': '-150px',
		'z-index': '0'
	}, 2000);
	
	$('#add').css({
		'transform': 'rotate(360deg) scale(1)',
	}, 2000);

	$('#moon').animate({
		top: '5%',
		left: '90%'
	}, 1500)

	$("#adjustForm").css({
		'top': '40%',
	});

	$("#content").animate({
		top: '15%'
	}, 1000)

} //点击标题后标题月亮进行移动，给内容腾出位置

function appendInner(ifo) {
	let name = $("<font class='owername'></font>").html("&nbsp;&nbsp;" + ifo['phonename_id'] + ":&nbsp;&nbsp;"); // 使用 jQuery 创建文本
	let text = $("<font class='owertext'></font>").html("<font class = 'texx'>" + ifo['publishcontent'] + "</font>");
	text.append("<img src='/static/talks/image/comment.png' class='comPic'/>");
	text.append($("</font>" + "<font class = 'time'>" + ifo['publishtime'] + "</font>" ))

	let coTex = ''
	//	console.log(ifo['comment'])
	if(ifo['comment']) {
		for(item of ifo['comment']) {
			coTex += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<font class = 'comName'>" + item['phonename_id'] + " @ " + item['towho'] + ":</font>" + "&nbsp;&nbsp;" + "<font class = 'comT' CID = " + item['phonename_id'] + ">" + item['commentcontent'] + "</font>" + "<font class = 'time'>" + 
			item['commenttime'] + "</font>" + "<br/>"
		}
	}
	let comment = $("<p class='comment'></p>").html(coTex);

	let nextin = $("<div class='inner'></div>")
	nextin.append(name)
	nextin.append(text)
	nextin.append(comment)
	$(nextin).attr('NID', ifo["name"])
	$("#content").prepend(nextin); // 追加新元素
}

function getNowTimeString() {
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;
	var day = now.getDate();
	var hour = now.getHours();
	var minute = now.getMinutes();
	var second = now.getSeconds();
	var nowdate = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
	return nowdate
}


//添加动态列表

$("#add").hover(function() {
	//	console.log(111)
	$(this).css({
		'transform': 'rotate(360deg) scale(2)',
	})
}, function() {
	$(this).css({
		'transform': 'rotate(-180deg) scale(1)',
	})
})
$(".comPic").hover(function() {
	$(this).attr('src', '/static/talks/image/commentx.png')
}, function() {
	$(this).attr('src', '/static/talks/image/comment.png')
})
$("#exit").hover(function() {
	$(this).attr('src', '/static/talks/image/exitx.png')
}, function() {
	$(this).attr('src', '/static/talks/image/exit.png')
})
//加号、退登、和评论图标的鼠标移动事件


var des = {} //作为多行输入框flag
$("#add").click(function() {
	$("#write").toggle()
	des['flag'] = 1
	$("#text").val("写下今天你想说的话吧！")
})


$("#reset").click(function() {
	$("#write").toggle()
})

$("#send").click(function() {
	$("#write").toggle()
	//	console.log(des)
	des['time'] = getNowTimeString();

	if(!des['flag']) {
		coT = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + "<font class = 'comName'>" + ID + " @ " + des['cid'] + ":</font>" + "&nbsp;&nbsp;" + "<font class = 'comT' CID = " + "session里的用户ID" + ">" + $("#text").val() + "</font>" + "</font>" + "<font class = 'time'>" + des['time'] + "</font>" + "<br/>"
		des['this'].append(coT);
		des['text'] =   $("#text").val();
		console.log(des);
		let comment={
			"commentcontent":des['text'],
			"commenttime":des['time'],
			"phonename_id":ID,
			"publishcontent_id":des['nid'],
			"towho":des['cid']
		};
		console.log(comment);
		$.ajax({
			url:"/addcomment/",
			type:"POST",
			async:false,
			data:comment,
			success:function(){console.log("应该成功了" + "传的值为" + comment)}
		})




	} else {

		//		console.log(des)
		appendInner({
			'publishtime': getNowTimeString(),
			'phonename_id': ID,
			'publishcontent': $("#text").val()
		});
		
		let D = {
			'publishtime': getNowTimeString(),
			'phonename_id': ID,
			'publishcontent': $("#text").val()
		}
		console.log(D);
		$.ajax({
			url:"/addcontent/",
			type:"POST",
			async:false,
			data:D,
			success:function(){console.log("应该成功了" + "传的值为" + D)}
		})
	}
})
//设置回复